<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="Author" content="FengYu">
    <title>demo</title>
    <style>
        *{margin:0;padding:0;font-family: Microsoft YaHei,serif;}
        li{list-style: none;}
        #box{
            position: absolute;
            top:100px;
            left:100px;
            width:100px;
            height: 100px;
            background: pink;
        }
        #sbox{
            position: absolute;
            bottom:0;
            right:0;
            width:5px;
            height: 5px;
            background: red;

        }
    </style>
</head>
<body>
<div id="box">
    <div id="sbox"></div>
</div>
<script>

    box.onmousedown=function (e) {
        e=e||window.event;
        var xDown = e.clientX,//获取鼠标的初始坐标
            yDown = e.clientY,//获取鼠标的初始坐标
            leftDown = this.offsetLeft,
            topDown = this.offsetTop;
        box.style.cursor = "pointer"

        document.onmousemove=function (e) {
            e = e||window.event;
            var xMove = e.clientX,
                yMove = e.clientY;
            box.style.left = leftDown + xMove - xDown + "px";
            box.style.top =topDown + yMove - yDown + "px";

        }
    };

    document.onmouseup=function () {
        box.style.cursor = "default";
        document.body.style.cursor = "default";
        this.onmousemove=null;
    }

    sbox.onmousedown=function (e) {
        e = e||window.event;
        e.cancelBubble=true;
        var xDown = e.clientX,
            yDown = e.clientY,
            boxW = box.clientWidth,
            boxH = box.clientHeight;
            document.body.style.cursor = "se-resize";
        document.onmousemove=function (e) {
            e = e||window.event;
            var xMove = e.clientX,
                yMove = e.clientY,
                x_ = xMove - xDown, //x变化量
                y_ = yMove - yDown, // y变化量
                width = Math.max(10,x_+boxW),
                height = Math.max(10,y_+boxH);
            box.style.width = width + "px";
            box.style.height = height + "px";
        }
    }

</script>
</body>
</html>